package pl.edu.mimuw.irs.rcp.controller.editor.bucket.command;

import org.eclipse.gef.commands.Command;

import pl.edu.mimuw.irs.core.model.analysis.History;
import pl.edu.mimuw.irs.rcp.controller.editor.bucket.Bucket;

public class RemoveRun extends Command {

	// *** Attributes

	private History run;
	private int index;
	private Bucket bucket;
	public History getRun() {
		return run;
	}
	public Bucket getBucket() {
		return bucket;
	}
	
	// *** Constructors
	
	public RemoveRun(Bucket bucket, History run) {
		this.run = run;
		this.index = bucket.indexOf(run);
		this.bucket = bucket;
	}
	
	// *** Methods
	
	public boolean canExecute() {
		return index >= 0 && super.canExecute();
	};
	
	@Override
	public void execute() {
		if (index < 0) return;
		getBucket().remove(index);
		super.execute();
	}
	
	@Override
	public void undo() {
		if (index < 0) return;
		getBucket().add(index, getRun());
		super.undo();
	}
}
